local hx__shandianti = fk.CreateSkill {
  name = "hx__shandianti",
  tags = { Skill.Compulsory , Skill.Switch },
}

hx__shandianti:addEffect(fk.TurnStart, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__shandianti.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYin then
      room:setPlayerMark(player, "@@hx__shandianti-ze", 0)
      room:addPlayerMark(player, "@@hx__shandianti-ping")
    else
      room:setPlayerMark(player, "@@hx__shandianti-ping", 0)
      room:addPlayerMark(player, "@@hx__shandianti-ze")
    end
    player:setSkillUseHistory(hx__shandianti.name, 0, Player.HistoryGame)
  end,
})

hx__shandianti:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__shandianti.name) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(5)
    local basic = table.filter(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end)
    local trick = table.filter(cards, function(id) return Fk:getCardById(id).type == Card.TypeTrick end)
    room:showCards(cards)
    room:askToGuanxing(player, {
      cards = cards,
      skill_name = hx__shandianti.name,
    })
    if player:getMark("@@hx__shandianti-ze") == 0 then
      local judge = {
        who = data.to,
        reason = "lightning",
        pattern = ".|2~9|spade",
      }
      room:judge(judge)
      local result = judge.card
      if result.suit == Card.Spade and result.number >= 2 and result.number <= 9 then
        room:damage{
          to = data.to,
          damage = 3,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
      if #trick > 0 then
        local car = room:askToDiscard(data.to, {
          min_num = #trick,
          max_num = #trick,
          prompt = "请弃置"..#trick.."张牌，否则不可响应此【杀】",
          skill_name = hx__shandianti.name,
          cancelable = true,
        })
        if #car == 0 then
          data.use.disresponsiveList = data.use.disresponsiveList or {}
          table.insert(data.use.disresponsiveList, data.to)
        end
      end
    else
      if #basic > 0 then
        data.additionalDamage = (data.additionalDamage or 0) + #basic
      end
    end
  end,
})

hx__shandianti:addEffect("targetmod", {
  name = "hx__shandianti",
  bypass_distances =  function(self, player, skill, card, to)
       return player:hasSkill(hx__shandianti.name) and player:getMark("@@hx__shandianti-ze") > 0 and card.trueName == "slash"
  end,
})

hx__shandianti:addEffect(fk.PreDamage, {
  anim_type = "offensive",
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__shandianti.name) and
      data.card and data.card.trueName == "slash" and player:getMark("@@hx__shandianti-ze") > 0
  end,
  on_use = function(self, event, target, player, data)
    local n = data.damage
    player.room:notifySkillInvoked(player, hx__shandianti.name)
    data:preventDamage()
    player.room:loseHp(data.to, n, hx__shandianti.name)
  end,
})



return hx__shandianti